package com.example.androdwithfluttertest2

import android.app.Application
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor


class MyApplication : Application() {
    private var flutterEngine: FlutterEngine? = null
    override fun onCreate() {
        super.onCreate()
        // 创建一个Flutter引擎
        flutterEngine = FlutterEngine(this)

        // 开始执行 Dart 代码来预热flutter引擎
        flutterEngine!!.getDartExecutor().executeDartEntrypoint(
            DartExecutor.DartEntrypoint.createDefault()
        )

        //缓存Flutter引擎用来开启FlutterActivity
        FlutterEngineCache
            .getInstance()
            .put("my_engine_id", flutterEngine)
    }
}